//
//  StoreListViewController.m
//  NordsonTesco
//
//  Created by mac on 16/6/25.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "StoreListViewController.h"
#import "StoreListTableViewCell.h"
#import "ShopDetailsViewController.h"

@interface StoreListViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UIView *navigationStoreListView;
}

@property (nonatomic,strong)UITableView *storeListTableView;
@end

@implementation StoreListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createStoreListTableView];
    // Do any additional setup after loading the view.
}
#pragma mark -- 创建tableview
- (void)createStoreListTableView{
    
    //navigation
    navigationStoreListView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,kScrernWidth, 64)];
    navigationStoreListView.backgroundColor = [UIColor colorWithRed:246/255.0 green:51/255.0 blue:11/255.0 alpha:1];
    [self.navigationController.view addSubview:navigationStoreListView];
    
    UIImageView *storeListImage = [[UIImageView alloc]initWithFrame:CGRectMake(navigationStoreListView.center.x - 80,35, 15, 15)];
    storeListImage.image = [UIImage imageNamed:@"zixun_search"];
    [navigationStoreListView addSubview:storeListImage];
    
    UILabel *storeListLabel = [[UILabel alloc]initWithFrame:CGRectMake(navigationStoreListView.center.x - 50,32, 60, 20)];
    storeListLabel.text = @"请输入商家名称";
    storeListLabel.textColor = [UIColor whiteColor];
    storeListLabel.font = [UIFont systemFontOfSize:12];
    [navigationStoreListView addSubview:storeListLabel];
    
    //搜索透明view
    UIView *storeListView = [[UIView alloc]initWithFrame:CGRectMake(navigationStoreListView.center.x - 90,30,180,25)];
    storeListView.backgroundColor = [UIColor whiteColor];
    storeListView.alpha = 0.3;
    storeListView.layer.masksToBounds = YES;
    storeListView.layer.cornerRadius = 15;
    [navigationStoreListView addSubview:storeListView];
    
    UIButton *storeListButon = [UIButton buttonWithType:UIButtonTypeCustom];
    storeListButon.frame = CGRectMake(navigationStoreListView.center.x - 90,30,180,25);
    [storeListButon addTarget:self action:@selector(storeListButonAction) forControlEvents:UIControlEventTouchUpInside];
    storeListButon.backgroundColor = [UIColor clearColor];
    storeListButon.layer.masksToBounds = YES;
    storeListButon.layer.cornerRadius = 15;
    [navigationStoreListView addSubview:storeListButon];
    
    //创建tableview
    _storeListTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,48, kScrernWidth,kScrernHeight-40) style:UITableViewStylePlain];
    _storeListTableView.delegate=self;
    _storeListTableView.dataSource=self;
    _storeListTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:_storeListTableView];
    
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0,64, kScrernWidth, 48)];
    backgroundView.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
    [self.view addSubview:backgroundView];
    
    NSArray *sclassify_array = @[@"综合排序",@"销量优先",@"选购热点",@"筛选"];
    NSInteger sclassifyTag = 110;
    for (int i = 0; i < 4; i++) {
        UIButton *sclassifyButon = [UIButton buttonWithType:UIButtonTypeCustom];
        sclassifyButon.frame = CGRectMake(0+kScrernWidth/4*i,0,kScrernWidth/4,48);
        [sclassifyButon addTarget:self action:@selector(searchButonAction:) forControlEvents:UIControlEventTouchUpInside];
        [sclassifyButon setTitle:[sclassify_array objectAtIndex:i] forState:UIControlStateNormal];
        [sclassifyButon setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
        sclassifyButon.tag = sclassifyTag++;
        sclassifyButon.titleLabel.font = [UIFont systemFontOfSize:15];
        sclassifyButon.backgroundColor = [UIColor clearColor];
        [backgroundView addSubview:sclassifyButon];
        
        UIView *verticalView = [[UIView alloc]initWithFrame:CGRectMake(kScrernWidth/4+kScrernWidth/4*i,73,1, 30)];
        verticalView.backgroundColor = [UIColor colorWithRed:212/255.0 green:212/255.0 blue:212/255.0 alpha:YES];
        [self.view addSubview:verticalView];
        //
    }
}
- (void)storeListButonAction{
    NSLog(@"搜索");
    
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    //    self.navigationController.navigationBarHidden = YES;
}
- (void)searchButonAction:(UIButton *)sender{
    switch (sender.tag) {
        case 110:{
            NSLog(@"综合排序");
        }
            break;
        case 111:{
            NSLog(@"销量优先");
        }
            break;
        case 112:{
            NSLog(@"选购热点");
        }
            break;
        case 113:{
            NSLog(@"筛选");
        }
            break;
        default:
            break;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 96;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    StoreListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"store"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"StoreListTableViewCell" owner:nil options:nil] firstObject];
    }
    //    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //    static NSString *identifer=@"cell";
    //    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifer];
    //    if (cell==nil) {
    //        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    //    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ShopDetailsViewController *shopDetailsViewC = [[ShopDetailsViewController alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    navigationStoreListView.hidden = YES;
    [self.navigationController  pushViewController:shopDetailsViewC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
